/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package game.platformer.combat;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import java.util.LinkedList;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.extension.physics.box2d.PhysicsConnector;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
/**
 *
 * @author cow
 */
public class Bullet {
	//var block-------------------
	private Sprite bulletImage;
	private Body phyBody;
        private PhysicsWorld mPhysicsWorld;
	//----------------------------

        //Initialize bullet
	public Bullet(Scene curScene, TextureRegion bulletTR,
                PhysicsWorld inptPhysicsWorld, float x, float y){
            //Set Variables
            bulletImage = new Sprite(x,y,bulletTR);
            
            this.mPhysicsWorld=inptPhysicsWorld;
            
            FixtureDef fd = PhysicsFactory.createFixtureDef(0, 0, 0);
            phyBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld,
                        bulletImage, BodyDef.BodyType.DynamicBody, fd);
            phyBody.setBullet(true);
            
            this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector
                    (bulletImage, phyBody,true,true));
            curScene.attachChild(bulletImage);
	}

	public void setPosition(float x, float y){
            phyBody.setTransform(x, y, 0);
	}

	public void setVelocity(Vector2 mVelocity){
            phyBody.setLinearVelocity(mVelocity);
	}
        
        public void enable(){
            //Wake up and start detecting collisions.
            phyBody.setActive(true);
            phyBody.setAwake(false);
        }
        public void disable(){
            //Put to sleep and ignoe collisions
            phyBody.setActive(false);
            phyBody.setAwake(true);
        }
}
